package day48;

import java.util.*;

public class MaxGap {
    public int findMaxGap(int[] A, int n) {
        // write code here
        int k = 1;
        int max = -1;
        while(k < n - 1) {
            int leftMax = A[0];
            int rightMax = A[n-1];
            for(int i = 0; i < k; i++) {
                if(leftMax < A[i]) {
                    leftMax = A[i];
                }
            }
            for(int i = k+1; i < n; i++) {
                if(rightMax < A[i]) {
                    rightMax = A[i];
                }
            }
            if(max < Math.abs(leftMax - rightMax)) {
                max = Math.abs(leftMax - rightMax);
            }
            k++;
        }
        return max;

    }
}